﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MVC.Models.Database;

namespace MVC.Controllers
{
    [Route("[action].html")]
    public class HomeController : Controller
    {
        private readonly MVCContext _db;
        public HomeController(MVCContext db)
        {
            _db = db;
        }
        public IActionResult Index(int Cateid, int Newid, int i, int id = 0, string oo = "")
        {
            if (Cateid != null && Cateid != 0)
            {
                //从数据库中获取与给定Id匹配的新闻列表
                var News = _db.News.Where(x => x.Cateid == Cateid).ToList();
                ViewData["News"] = News;  //将获取的新闻列表存储在ViewData中
                var Cate = _db.CateNews.ToList();
                ViewData["Cates"] = Cate;
            }
            else
            {
                var News = _db.News.ToList();
                ViewData["News"] = News;
                var Cate = _db.CateNews.ToList();
                ViewData["Cates"] = Cate;
            }
                ViewData["cateId"] = Cateid;
            return View();
        }
        public IActionResult Detail()
        {
            return View();
        }
    }
}
